<?php

namespace Beerus\Modules\Category\Controllers;

use App\Http\Controllers\Controller;
use Doraemon\service\Category as sCategory;
use Doraemon\model\Category as mCategory;
use Encore\Admin\Controllers\Dashboard;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Column;
use Encore\Admin\Layout\Content;
use Encore\Admin\Layout\Row;
use Illuminate\Http\Request;

class SearchController extends Controller
{
    public function select()
    {
        $categories = sCategory::getAllCategorys([mCategory::STATUS_USING, mCategory::STATUS_HIDE]);

        $categories = array_values($categories);

        array_walk($categories,function (&$v1,$key){

            if(isset($v1['children'])) {
                $v1['children'] = array_values($v1['children']);

                array_walk($v1['children'], function (&$v2) {
                    if (isset($v2['children'])) {
                        $v2['children'] = array_values($v2['children']);

                        array_walk($v2['children'], function (&$v3) {
                            if (isset($v3['children'])) {
                                $v3['children'] = array_values($v3['children']);
                            }
                        });
                    }
                });
            }
        });

        return response()->json($categories);
    }

}
